﻿<style>
#role, #role2 , #role3{padding-bottom:5px; padding-top:5px;border:none;}
.row .span-2 strong{font-weight:bold;}
#work2, #o2o_work{padding:10px 10px 10px 5px;}
#work_obj, #work2_obj, #work3_obj{border-bottom:1px dotted #e8e8e8;}
#work3_obj{border:none;}
</style>
<form action="index.php?ctl=users&act=addnew&finder_id=a9b819" id="user-edit-form" method="post">
  <div class="tableform">
    <h5>基本信息 <{help docid="101" type="link"}><{t}>点击查看帮助<{/t}><{/help}></h5>
    <div class="division">

      <table cellspacing="0" cellpadding="0" width="100%">
        <tbody>
          <tr>
            <th>
              <em class="red">*</em>
              <label><{t}>用户名：<{/t}></label>
            </th>
            <td width="40%">
              <input type="text" id="dom_el_ea78c40"  vtype="required"  name="pam_account[login_name]" title="<{t}>用户名：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
            <th>
              <label><{t}>工号：<{/t}></label>
            </th>
            <td>
              <input type="text" id="dom_el_ea78c46" required="" name="op_no" title="<{t}>工号：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
          </tr>

          <tr>
            <th><em class="red">*</em>
              <label><{t}>密码：<{/t}></label>
            </th>
            <td>
              <input type="password" id="dom_el_ea78c41" vtype="required" name="pam_account[login_password]" title="<{t}>密码：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
            <th>
              <label><{t}>备注：<{/t}></label>
            </th>
            <td>
              <input type="text" id="dom_el_ea78c47" required="" name="memo" title="<{t}>备注：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
          </tr>

          <tr>
            <th>
              <em class="red">*</em>
              <label><{t}>确认密码：<{/t}></label>
            </th>
            <td>
              <input type="password" id="dom_el_ea78c42" vtype="required" name="re_password" title="<{t}>确认密码：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
          </tr>

          <tr>
            <th>
              <em class="red">*</em>
              <label><{t}>姓名：<{/t}></label>
            </th>
            <td>
              <input type="text" id="dom_el_ea78c43" vtype="required"  name="name" title="<{t}>姓名：<{/t}>" class="x-input " autocomplete="off"/>
            </td>
          </tr>

          <tr>
            <th>
              <em class="red">*</em>
              <label><{t}>启用：<{/t}></label>
            </th>
            <td>
              <select id="dom_el_ea78c45" required="1" name="status" type="select" title="<{t}>启用：<{/t}>" class="x-input-select inputstyle">
                <option value="0"><{t}>否<{/t}></option>
                <option value="1" selected="selected"><{t}>是<{/t}></option>
              </select>
            </td>
          </tr>

          <tr>
            <th></th>
            <td>
              <input id="dom_el_ea78c44" value=0 name="super" type="hidden" title="<{t}>超级管理员：<{/t}>" class="x-input-select inputstyle"></input>
            </td>
          </tr>


        </tbody>
      </table>
    </div>
  </div>
  <div class="tableform">
        <h5>工作组</h5>
        <div class="gridlist clearfix">
                <div class="row" id="role">
                    <div class="row-line role-list" style="padding:5px;">
                        <div class="span-2"><strong>订单角色</strong></div>
                        <div class="span-13">
                            <{foreach from=$workgroup_order item=item}>
                            <div class="span-auto">
                                <label><input class="role" type="checkbox" value="<{$item.role_id}>" name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                            </div>
                            <{/foreach}>
                        </div>
                    </div>
                </div>
                <div class="row" id="work_obj" style="display:none;">
                    <div class="row-line role-list" style="padding:10px;">
                        <div id="work" style="padding-left:70px;">&nbsp;</div>
                    </div>
                </div>
                
                <div class="row" id="role2">
                    <div class="row-line role-list" style="padding:5px;">
                        <div class="span-2"><strong>仓库角色</strong></div>
                        <div class="span-13">
                            <{foreach from=$workgroup_branch item=item}>
                            <div class="span-auto">
                                <label><input class="role2" type="checkbox" value="<{$item.role_id}>" name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                            </div>
                            <{/foreach}>
                        </div>
                    </div>
                </div>
                <div class="row" id="work2_obj" style="display:none;">
                    <div class="row-line role-list" id="work2">
                    </div>
                    <input type="hidden" id="work3" value=""></input>
                </div>
                
                
                <div class="row" id="role3">
                    <div class="row-line role-list" style="padding:5px;">
                        <div class="span-2"><strong>门店角色</strong></div>
                        <div class="span-13">
                            <{foreach from=$workgroup_o2o_branch item=item}>
                            <div class="span-auto">
                                <label><input class="role3" type="checkbox" value="<{$item.role_id}>" name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                            </div>
                            <{/foreach}>
                        </div>
                    </div>
                </div>
                <div class="row" id="work3_obj" style="display:none;">
                    <div class="row-line role-list" id="o2o_work">
                    </div>
                </div>

        </div>
  </div>
</form>
<{area inject=".mainFoot"}>
<div class="table-action">
  <table width="100%" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <td><{button class="btn-primary" id="user-edit-form-submit" type="submit" label=$___b2c="确定"|t:'b2c'}></td>
      </tr>
    </tbody>
  </table>
</div>
<{/area}>
<script>
//订单角色
var show_group = 3;
//仓库角色
var show_branch = 2;
//门店角色
var show_o2o_branch = 99;

(function(){
    $$('.role').addEvent('click',function(e){
       //订单权限
      var show_group_info = document.getElementById("work").innerHTML;
      //仓库权限
      var show_branch_info = document.getElementById("work2").innerHTML;
      var checkedEl = $ES('input.role:checked');

      var checkedName = [];
      checkedEl.each(function(cel,k){
        checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
      });
    //获取仓库角色的信息
        var checked_branch = $ES('input.role2:checked');
        var checkedName_branch  = [];
        checked_branch.each(function(cel,k){
            checkedName_branch[k] = encodeURIComponent(cel.value=cel.value.trim());
          });
      
      
      new Request({
          url:'index.php?app=desktop&ctl=users&act=detail_ground',
          //update:$('work'),
          method:'post',
          data:'role='+show_group+'&checkedName='+JSON.encode(checkedName)+'&checkedName_branch='+JSON.encode(checkedName_branch)+'&name='+encodeURIComponent(this.value=this.value.trim()),
            onComplete:function(result){
                  var result = JSON.decode(result);
                  var group_Info = document.getElementById("work");
                  var branch_info = document.getElementById("work2");
                  //订单确认下拉
                  //group_Info.innerHTML = result['group_info']||'';
                  if(result['group_info'])
                  {
                      $('work_obj').setStyle('display','');
                      group_Info.innerHTML = result['group_info'];
                  }
                  else
                  {
                      group_Info.innerHTML = '';
                      $('work_obj').setStyle('display','none');
                  }
                  
                  //选择仓库
                  //branch_info.innerHTML = result['branch_info']||'';
                  if(result['branch_info'])
                  {
                      $('work2_obj').setStyle('display','');
                      branch_info.innerHTML = result['branch_info'];
                  }
                  else
                  {
                      branch_info.innerHTML = '';
                      $('work2_obj').setStyle('display','none');
                  }
              }
      }).send();
      // $('work').setStyle('display','block');
    });
  $$('.role2').addEvent('click',function(e){
    var checkedEl = $ES('input.role2:checked');

    var checkedName = [];
    checkedEl.each(function(cel,k){
    checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
    });
    
    //获取订单角色的信息
    var checked_group = $ES('input.role:checked');
    var checkedName_group  = [];
    checked_group.each(function(cel,k){
        checkedName_group[k] = encodeURIComponent(cel.value=cel.value.trim());
      });
    new Request({
      url:'index.php?app=desktop&ctl=users&act=detail_ground',
      //update:$('work2'),
      method:'post',
      data:'role='+show_branch+'&checkedName='+JSON.encode(checkedName)+'&checkedName_group='+JSON.encode(checkedName_group)+'&name='+encodeURIComponent(this.value=this.value.trim()),
      onComplete:function(result){
          var result = JSON.decode(result);
          var group_Info = document.getElementById("work");
          var branch_info = document.getElementById("work2");
          //设置双重权限的标识位信息
          var branch_work3 = document.getElementById("work3");
          //订单确认下拉
          //group_Info.innerHTML = result['group_info']||'';
          if(result['group_info'])
          {
              $('work_obj').setStyle('display','');
              group_Info.innerHTML = result['group_info'];
          }
          else
          {
              group_Info.innerHTML = '';
              $('work_obj').setStyle('display','none');
          }
          
          //选择仓库
          //branch_info.innerHTML = result['branch_info']||'';
          if(result['group_info']){
              //1标示存在双重权限
              branch_work3.value = '1';
          }else{
              branch_work3.value = '0';
          }
          
          if(result['branch_info'])
          {
              $('work2_obj').setStyle('display','');
              branch_info.innerHTML = result['branch_info'];
          }
          else
          {
              branch_info.innerHTML = '';
              $('work2_obj').setStyle('display','none');
          }
      }
    }).send();
    // $('work').setStyle('display','block');
  });
    $('dom_el_ea78c44').addEvent('change',function(e){
      value = $('dom_el_ea78c44').value;
      if(value==0){
        $('role').setStyle('display','block');
        //$('work').setStyle('display','block');
        
        $('work_obj').setStyle('display','block');
        $('role2').setStyle('display','block');
      }
      else{
        $('role').setStyle('display','none');
        //$('work').setStyle('display','none');
        
        $('work_obj').setStyle('display','none');
        $('role2').setStyle('display','none');
      }
    });


    var _form = $('user-edit-form');
    var btn =$('user-edit-form-submit');
    var finder = finderGroup['<{$env.get.finder_id}>'];
    _form.store('target',{
      onComplete:function(){
      },
      onSuccess:function(response){
        var hash_res_obj = JSON.decode(response);
        if (hash_res_obj.success != undefined && hash_res_obj.success != ""){
          try{
            var _dialogIns = btn.getParent('.dialog').retrieve('instance');
          }catch(e){}

          if(_dialogIns){
            _dialogIns.close();

          }
        }
      }
    });

    btn.addEvent('click',function(){
      _form.fireEvent('submit',{stop:$empty});
    });


    $$('.role3').addEvent('click',function(e)
    {
        var checkedEl = $ES('input.role3:checked');
    
        var checkedName = [];
        checkedEl.each(function(cel,k){
            checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
        });
        
        //获取订单角色的信息
        var checkedName_group  = [];
        
        new Request({
          url:'index.php?app=desktop&ctl=users&act=detail_ground',
          method:'post',
          data:'role='+show_o2o_branch+'&checkedName='+JSON.encode(checkedName)+'&checkedName_group='+JSON.encode(checkedName_group)+'&name='+encodeURIComponent(this.value=this.value.trim()),
          onComplete:function(result){
              var result = JSON.decode(result);
              
              //选择o2o门店仓库
              var o2o_branch_info = document.getElementById("o2o_work");
              if(result['o2o_branch_info'])
              {
                  $('work3_obj').setStyle('display','');
                  o2o_branch_info.innerHTML = result['o2o_branch_info'];
              }
              else
              {
                  o2o_branch_info.innerHTML = '';
                  $('work3_obj').setStyle('display','none');
              }
          }
        }).send();
    });
})();
</script>
